#include <stdio.h>

#include "singleton.h"

/*---------------------------------------------------------------------------*/

Singleton* Singleton::p_instance = 0;
SingletonDestroyer Singleton::destroyer;

/*---------------------------------------------------------------------------*/

SingletonDestroyer::~SingletonDestroyer()
{
	delete p_instance;
}

void SingletonDestroyer::init( Singleton* p )
{
	p_instance = p;
}

/*---------------------------------------------------------------------------*/

Singleton::Singleton(): _a(0) {}

Singleton::~Singleton() {}

Singleton* Singleton::getInstance()
{
	if( !p_instance )
	{
		p_instance = new Singleton();
		destroyer.init( p_instance );
	}
	return p_instance;
}

void Singleton::set( int a )
{
	_a = a;
}

int Singleton::get()
{
	return _a;
}

/*---------------------------------------------------------------------------*/
